<template>
	<cl-crud>
		<div class="pb-1 flex flex-justify-end">
			<el-button @click="save" :loading="loading">保 存</el-button>
		</div>
		<oa-workflow v-loading="loading" ref="flow" style="flex:1" :data="info" />
	</cl-crud>
</template>
<script>
let startNode = {
	nodeName: "发起人",
	type: 0,
	priorityLevel: "",
	settype: 1,
	selectMode: "",
	selectRange: "",
	directorLevel: "",
	examineMode: "",
	noHanderAction: "",
	examineEndDirectorLevel: "",
	ccSelfSelectFlag: "",
	conditionList: [],
	nodeUserList: [],
	childNode: null
};
import dataJson from "./workflow.json";
import { isEmpty } from "cl-admin/utils";
export default {
	data() {
		return {
			loading: false,
			info: {
				workFlowType: 1,
				nodeConfig: startNode
			}
		};
	},
	created() {
		this.getInfo();
	},
	methods: {
		// 获取信息
		async getInfo() {
			let info = { ...dataJson.data };
			let nodeConfig = this.deepNodeConfig(info.nodeConfig);
			if (isEmpty(nodeConfig)) {
				nodeConfig = {
					...startNode
				};
			}
			this.info = {
				...info,
				enable: info.enable || 1,
				workFlowType: info.workFlowType || 1,
				nodeConfig
			};
		},
		save() {},
		// 递归处理节点
		deepNodeConfig(nodeConfig) {
			function deep(data = {}) {
				if (!isEmpty(data.conditionNodes)) {
					data.conditionNodes.forEach(node => {
						deep(node);
					});
				}
				if (isEmpty(data.childNode)) {
					delete data.childNode;
					return;
				}
				if (!isEmpty(data.approverUserList)) {
					delete data.approverUserList;
					return;
				}
				deep(data.childNode);
			}
			deep(nodeConfig);
			return nodeConfig;
		}
	}
};
</script>
